<style lang="less">
    @import '../../styles/common.less';
    @import '../tables/components/table.less';
</style>
<template>
    <div>
        <form action="" style="margin: 5px 0">
            <Input v-model="name"   placeholder="根据用户名查找"  style="width: 200px;margin-right: 3px;"></Input>
            <Input v-model="phone"  placeholder="根据手机号查找"  style="width: 200px"></Input>
            <div style="float: right">
            <Button type="info" style="float: right;margin-right: 5px" @click="load (1)">查询</Button>
            </div>
        </form>
        <Table :loading="loading" refs="table1" @on-selection-change="changeNum" @on-delete="handleDel" :data="Message" :columns="columnsList"></Table>
        <Modal
                v-model="modal1"
                class="userListInfoWrap"
                title="用户详情"
        >
            <p><span class="userListInfo">用户名:</span><span v-text="userListInner.username"></span></p>
            <p><span class="userListInfo">手机号:</span><span v-text="userListInner.phone"></span></p>
            <p><span class="userListInfo">钱包地址:</span><span v-text="userListInner.mywalletAddress"></span></p>

            <p><span class="userListInfo">钱包USDI数量:</span><span v-text="userListInner.mywalletUsdnumber"></span></p>
            <p><span class="userListInfo">钱包AITC数量:</span><span v-text="userListInner.mywalletAitcnumber"></span></p>

            <p><span class="userListInfo">锁仓账户释放AITC:</span><span v-text="userListInner.unlockAitc"></span></p>
            <p><span class="userListInfo">锁仓账户锁仓AITC:</span><span v-text="userListInner.lockAitc"></span></p>

            <p><span class="userListInfo">币币账户USDI:</span><span v-text="userListInner.usd"></span></p>
            <p><span class="userListInfo">币币账户冻结USDI:</span><span v-text="userListInner.freezeUsd"></span></p>
            <p><span class="userListInfo">币币账户AITC:</span><span v-text="userListInner.aitc"></span></p>
            <p><span class="userListInfo">币币账户冻结AITC:</span><span v-text="userListInner.freezeAitc"></span></p>

            <p><span class="userListInfo">释放矿石:</span><span v-text="userListInner.unlockOre"></span></p>
            <p><span class="userListInfo">锁仓矿石:</span><span v-text="userListInner.basicOre"></span></p>
            <p><span class="userListInfo">转入矿石:</span><span v-text="userListInner.shiftOre"></span></p>
            <p><span class="userListInfo">利润矿石:</span><span v-text="userListInner.returnOre"></span></p>

            <p><span class="userListInfo">CTC可用矿石:</span><span v-text="userListInner.usadbleMineral"></span></p>
            <p><span class="userListInfo">CTC冻结矿石:</span><span v-text="userListInner.frostMineral"></span></p>


            <!--<p><span class="userListInfo">矿石总量:</span><span v-text="userListInner.oreSum"></span></p>-->
            <p><span class="userListInfo">矿机等级:</span><span v-text="userListInner.oreLevelId"></span></p>
            <p><span class="userListInfo">矿机锁仓金额:</span><span v-text="userListInner.lockPriciple"></span></p>
            <p><span class="userListInfo">矿机释放金额:</span><span v-text="userListInner.freePrinciple"></span></p>
            <p><span class="userListInfo">静态总收益:</span><span v-text="userListInner.staticEarning"></span></p>
            <p><span class="userListInfo">动态总收益:</span><span v-text="userListInner.dynamicEarnings"></span></p>
            <!--<p><span class="userListInfo">释放动态收益:</span><span v-text="userListInner.initPrinciple"></span></p>-->
            <p><span class="userListInfo">CTC-USDI:</span><span v-text="userListInner.ctcUsdi"></span></p>

        </Modal>
        <Modal
                v-model="modal2"
                title="修改"
               >
            <Form ref="formValidate" :model="changeInner"  :rules="ruleValidate" :label-width="100">
                <Row :gutter="16">
                    <Col span="12">
                        <FormItem label="钱包USDI数量" prop="myUsd">
                            <Input v-model="changeInner.myUsd"   style="margin-right: 3px;"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="钱包AITC数量"  prop="myAitc">
                        <Input v-model="changeInner.myAitc"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12">
                        <FormItem label="AITC锁仓数量"  prop="lockAitc">
                            <Input v-model="changeInner.lockAitc"  style="margin-right: 3px;"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem label="AITC释放数量"  prop="lockUpAitc">
                            <Input v-model="changeInner.lockUpAitc"   style="margin-right: 3px;"></Input>
                        </FormItem>
                    </p>
                    </Col>
                </Row>
             <Row :gutter="16">
                    <Col span="12">
                        <FormItem label="矿石释放数量"  prop="lockOre">
                            <Input v-model="changeInner.lockOre"   style="margin-right: 3px;"></Input>
                        </FormItem>
                    </Col>
                    <Col span="12">
                        <FormItem label="矿石转入数量"  prop="lockShifeore">
                            <Input v-model="changeInner.lockShifeore"   style="margin-right: 3px;"></Input>
                        </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12">
                    <FormItem label="利润矿石数量"  prop="returnOre">
                        <Input v-model="changeInner.returnOre"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="矿石锁仓数量"  prop="basicOre">
                        <Input v-model="changeInner.basicOre"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>

                </Row>
                <Row :gutter="16">
                    <Col span="12">
                    <FormItem label="BB账户USDI"  prop="bbcUsd">
                        <Input v-model="changeInner.bbcUsd"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="BB账户AITC"  prop="bbcAitc">
                        <Input v-model="changeInner.bbcAitc"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                </Row>
                <Row :gutter="16">
                    <Col span="12">
                    <FormItem label="CTC矿石"  prop="ctcOre">
                        <Input v-model="changeInner.ctcOre"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                    <Col span="12">
                    <FormItem label="CTC-USDI"  prop="ctcUsdi">
                        <Input v-model="changeInner.ctcUsdi"   style="margin-right: 3px;"></Input>
                    </FormItem>
                    </Col>
                </Row>
            </Form>
            <div slot="footer">
                <Button type="primary" @click="sub('formValidate')">保存</Button>
            </div>
        </Modal>
        <Page :total="pageNum" :page-size="pageSize"  style="text-align: center;margin-top: 15px;" show-total @on-page-size-change='pageSizes'  show-elevator show-sizer @on-change="pageChange"></Page>

    </div>
</template>
<script>
    import $http from '../../utils/axiosWrap'
    import canEditTable from '../tables/components/canEditTable.vue'
    import Cookies from 'js-cookie';

    export default {
        data() {
            return {
                loading: true,
                Message:[],
                admin:true,
                modal1:false,
                modal2:false,
                userListInner:{},
                changeInner:{
                    id:'',
                    myUsd:'',
                    myAitc:'',
                    lockAitc:'',
                    lockUpAitc:'',
                    lockOre:'',
                    lockShifeore:'',
                    basicOre:'',
                    returnOre:'',
                    bbcUsd:'',
                    bbcAitc:'',
                    kssc:'',
                    ctcOre:'',
                    ctcUsdi:''
                },
                columnsList: [
                    {
                        title: '序号',
                        width: 80,
                        align: 'center',
                        render: (h, params) => {
                            return  params.index + (this.initPage- 1) * this.pageSize + 1
                        }
                    },
                    {
                        title: '用户名',
                        align: 'center',
                        key: 'username',
                        editable: true
                    },
                    {
                        title: '手机号',
                        align: 'center',
                        key: 'phone',
                        editable: true
                    },
                    {
                        title: 'USDI数量',
                        align: 'center',
                        key: 'usd',
                        editable: true
                    },
                    {
                        title: '冻结USDI',
                        align: 'center',
                        key: 'freezeUsd',
                        editable: true
                    },
                    {
                        title: '锁仓AITC',
                        align: 'center',
                        key: 'lockAitc',
                        editable: true
                    },
                    {
                        title: '释放AITC',
                        align: 'center',
                        key: 'unlockAitc',
                        editable: true
                    },
                    {
                        title: '冻结矿石',
                        align: 'center',
                        key: 'frostMineral',
                        editable: true
                    },
                    {
                        title: '释放矿石',
                        align: 'center',
                        key: 'unlockOre',
                        editable: true
                    },
                    {
                        title: '操作',
                        align: 'center',
                        width: 170,
                        render: (h, params) => {
                            if( Cookies.get('access') == 0){
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'success',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.info(params)
                                            }
                                        }
                                    }, '查看'),
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.change(params)
                                            }
                                        }
                                    }, '编辑')

                                ]);
                            }else{
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'success',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.info(params)
                                            }
                                        }
                                    }, '查看')
                                ]);
                            }
                        }
                    }
                ],
                name: '',
                phone: '',
                ruleValidate: {
                    myUsd: [
                        { required: true, message: '钱包USDI数量不得为空', trigger: 'blur' }
                    ],
                    myAitc: [
                        { required: true, message: '钱包AITC数量不得为空', trigger: 'blur' }
                    ],
                    lockAitc: [
                        { required: true, message: 'AITC锁仓数量不得为空', trigger: 'blur' }
                    ],
                    lockUpAitc: [
                        { required: true,   message: 'AITC释放数量不得为空', trigger: 'blur' }
                    ],
                    lockOre: [
                        { required: true,  message: '矿石释放数量不得为空', trigger: 'blur' }
                    ],
                    lockShifeore: [
                        { required: true,  message: '矿石转入数量不得为空', trigger: 'blur' }
                    ],
                    returnOre: [
                        { required: true,  message: '利润矿石数量不得为空', trigger: 'blur' }
                    ],
                    basicOre: [
                        { required: true,  message: '矿石锁仓数量不得为空', trigger: 'blur' }
                    ],
                    bbcUsd: [
                        { required: true,  message: 'BB账户USDI数量不得为空', trigger: 'blur' }
                    ],
                    bbcAitc: [
                        { required: true,  message: 'BB账户AITC数量不得为空', trigger: 'blur' }
                    ],
                    ctcOre: [
                        { required: true,  message: 'CTC矿石数量不得为空', trigger: 'blur' }
                    ],
                    kssc: [
                        { required: true,  message: 'CTC锁仓数量不得为空', trigger: 'blur' }
                    ],
                    ctcUsdi: [
                        { required: true,  message: 'CTC-USDI矿石数量不得为空', trigger: 'blur' }
                    ]
                },
                pageNum:1,
                initPage:1,
                pageSize:10
            }
        },
        created: function () {
            this.load()
        },
        methods: {
            pageChange(index){
                this.initPage = index
                this.loading = true
                this.load ()
            },
            handleDel (val, index) {
                this.$Message.success('删除了第' + (index + 1) + '行数据');
            },
            load (index){
                let _this = this
                _this.loading = true
                let params = new URLSearchParams()
                if(index == '1'){
                    _this.initPage = 1
                }
                _this.name += ''
                _this.phone += ''
                params.append('username',_this.name)
                params.append('phone',_this.phone)
                params.append('page',_this.initPage)
                params.append('pageSize',_this.pageSize)
                $http.post('/backgroundUserassets/findAllUserassets',params).then(function (res) {
                    if(res.suc){
                    _this.Message = res.result.rows
                    _this.pageNum = res.result.total
                    _this.loading = false
                }else{
                    if(res.msg == "请先登录"){
                        _this.$Message.error('请重新登录！');
                    }else{
                        _this.$Message.error(res.msg);
                    }
                }
                })
            },
            changeNum (val){
            },
            info(val){
                this.modal1 = true
                this.userListInner = val.row
            },
            change(val){
                console.log(val)
                this.modal2 = true
                this.changeInner.id=val.row.userId +''
                this.changeInner.myUsd=val.row.mywalletUsdnumber +''
                this. changeInner.myAitc=val.row.mywalletAitcnumber +''
                this.changeInner.lockAitc=val.row.lockAitc +''
                this.changeInner.lockUpAitc=val.row.unlockAitc +''
                this.changeInner.lockOre=val.row.unlockOre +''
                this.changeInner.basicOre=val.row.basicOre +''
                this.changeInner.lockShifeore=val.row.shiftOre +''
                this.changeInner.returnOre=val.row.returnOre +''
                this.changeInner.bbcUsd=val.row.usd +''
                this.changeInner.bbcAitc=val.row.aitc +''
                this.changeInner.ctcOre=val.row.usableMineral +''
                this.changeInner.ctcUsdi=val.row.usableUsdi +''

                console.log(val.row)

            },
            remove(val){
                console.log(val)
            },
            sub(name){
                let _this = this
                this.changeInner.id += ''
                this.changeInner.myUsd += ''
                this. changeInner.myAitc += ''
                this.changeInner.lockAitc += ''
                this.changeInner.lockUpAitc += ''
                this.changeInner.lockOre += ''
                this.changeInner.lockShifeore += ''
                this.changeInner.returnOre += ''
                this.changeInner.bbcUsd += ''
                this.changeInner.basicOre += ''

                this.changeInner.bbcAitc += ''
                _this.changeInner.ctcOre += ''
                _this.changeInner.ctcUsdi += ''

                _this.$refs[name].validate((valid) => {
                    if (valid) {
//                        if(_this.changeInner.aitcTotal/1 == _this.changeInner.aitcLock / 1 + _this.changeInner.aitcRelease / 1){
                            let params = new URLSearchParams()
                            params.append('userId',_this.changeInner.id)
                            params.append('sysEnglishName',Cookies.get('user'))
                            params.append('myUsd',_this.changeInner.myUsd)
                            params.append('myAitc',_this.changeInner.myAitc)
                            params.append('lockAitc',_this.changeInner.lockAitc)
                            params.append('lockUpAitc',_this.changeInner.lockUpAitc)
                            params.append('lockOre',_this.changeInner.lockOre)
                            params.append('lockShifeore',_this.changeInner.lockShifeore)
                            params.append('basicOre',_this.changeInner.basicOre)
                            params.append('returnOre',_this.changeInner.returnOre)
                            params.append('bbcUsd',_this.changeInner.bbcUsd)
                            params.append('bbcAitc',_this.changeInner.bbcAitc)
                            params.append('ctcOre',_this.changeInner.ctcOre)
                            params.append('ctcUsdi',_this.changeInner.ctcUsdi)

                        $http.post('/backgroundUserassets/update',params).then(function (res) {
                                    if(res.suc){
                                        _this.modal2 = false
                                        _this.loading = true
                                        _this.load()
                                        _this.$Message.info('修改成功');
                                    }else{
                                        _this.$Message.info('修改失败');
                                    }
                                })
                    } else {
                        _this.$Message.error('信息填写有误!')
                    }
                })

            },
            cancel(){
            },
            pageSizes(val){
                this.pageSize = val
                this.load(1)
            }
        }
    }
</script>
<style>
    .userListInfo{
        display: inline-block;
        width: 120px;
    }
    .userListInfoWrap p{
        line-height: 26px;
    }
</style>

